<template>
  <div>
    <div>
      <h4 style="margin:0 0 10px 0">订单管理 </h4>
      <el-row style="margin-bottom:10px">
        <el-col :span="18" >
          <div style="display:flex;align-items:center">
            <span>选择时间:</span>
           <el-date-picker v-model="value5" type="datetimerange" :picker-options="pickerOptions2" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" align="right"> </el-date-picker>
            <span>类别:</span>
            <el-select v-model="value" style="width:80px" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
            <span>订单状态:</span>
            <el-select v-model="oderVal" style="width:100px" placeholder="请选择">
              <el-option v-for="item in oderStatus" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span="6" style="text-align:right">
          <el-input v-model="sheachValue" style="width:150px" placeholder="输入搜索内容"></el-input>
          <el-button type="primary" @click="seachFun">搜索</el-button>
        </el-col>
      </el-row>
      
      <el-table :data="tableData" border style="width: 100%" >
        <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
        
        <el-table-column prop="channelOrderId" label="单号"> </el-table-column>      
        <el-table-column prop="createTime" label="支付时间">
         <template slot-scope="scope"> {{timeFun(scope.row.payTime)}}</template>
        </el-table-column>      
        <el-table-column prop="product.type" label="类别"> </el-table-column>      
        <el-table-column prop="amount" label="消费金额"> </el-table-column>      
        <el-table-column prop="product.title" label="项目名"> </el-table-column>      
        <el-table-column prop="hospital.name" label="商家"> </el-table-column>      
        <!-- <el-table-column prop="page_view" label="有效期"> </el-table-column>       -->
        <el-table-column prop="status" label="订单状态">
          <template slot-scope="scope">
            <div>
            <span v-if="scope.row.useStatus == 0"> 未使用</span>
            <span v-else-if="scope.row.useStatus == 1 || scope.row.useStatus == 3" class="green"> 已使用</span>
            <span v-else-if="scope.row.useStatus == 2" class="red">已过期</span>
            
          </div>  
          </template>  
        </el-table-column>       
      </el-table>
     
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'

  export default {
    data() {
      var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入关键字'));
        } else {
          callback();
        }
      };
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        currentPage4: 1,//分野  
        total:0,      
        tableData: [],
        page:1,
        pageSize:10,
        sheachValue:'',
         pickerOptions2: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value5: '',
        oderVal:'', //选择订单
        oderStatus:[
          {value:0,label:'未付款'},
          {value:1,label:'付款成功'},
          {value:2,label:'付款失败'},
          {value:3,label:'退款中'},
          {value:4,label:'退款成功'},
          {value:5,label:'退款失败'},
        ],
        options: [{
          value: '选项1',
          label: '黄金糕'
        },{
          value: '选项5',
          label: '北京烤鸭'
        }],
        value: ''
       
      }
    },
    created() {
      this.getlist()
    },
    methods: {
       getlist() {
        const parm ={
          "pageIndex":this.page,
          "pageSize":this.pageSize,
        };
        if(this.sheachValue){
          parm.keyword = this.sheachValue;
        }
        Http.getBuyList(parm)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
          
        })
        .catch( error => {
          
        })
      },  
      timeFun(val) {
        return getTime(val)
      },
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        
      },
     
      seachFun(){
        
        this.getlist()
      }
    }
  }
</script>